package cn.itcast.dewu.controller;

import cn.itcast.dewu.dto.Result;
import cn.itcast.dewu.pojo.Goods;
import cn.itcast.dewu.service.GoodsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/goods-order")
public class GoodsOrderController {
    @Autowired
    private GoodsOrderService goodsOrderService;
    /*
    * 购买普通商品
    * */
    @PostMapping("/buy-goods/{id}")
    public Result buyGoods(@PathVariable("id") Long goodsId) {
        return goodsOrderService.buyGoods(goodsId);
    }

    /*
     * 购买特价商品
     * */
    @PostMapping("/special-goods/{id}")
    public Result buySpecialGoods(@PathVariable("id") Long goodsId) {
        return goodsOrderService.buySpecialGoods(goodsId);
    }


   /* *
   加入购物车

    * */
    @PostMapping("/savecart/{id}")
    public Result saveGoodToCart(@PathVariable("id") Long goodsId) {
        return goodsOrderService.saveGoodToCart(goodsId);
    }


    /*
    * 查看购物车
    * */

    @GetMapping("/lookcart")
    public Result lookCart() {
        return goodsOrderService.lookCart();
    }

    /*
     *
     * 清空购物车
     * */
    @PutMapping("/remove/cart")
    public Result removeCart(@RequestBody Map<String, Long> map) {
        return goodsOrderService.removeCart(map);
    }
}
